package com.dushibao.utils.encryption;

import java.nio.charset.StandardCharsets;
import java.util.Base64;

public class Base64Util {

    /***
     * BASE64解密
     * @param key
     * @return
     * @throws Exception
     */
    public static byte[] decryBASE64(String key) {

        return Base64.getDecoder().decode(key);
    }

    /***
     * BASE64加密
     * @param key
     * @return
     * @throws Exception
     */
    public static String encryptBASE64(byte[] key) {
        return Base64.getEncoder().encodeToString(key);
    }

    public static void main(String[] args) {
        //原文
        String src = "HellJava";
        //加密后的密文
        String encrtypt = encryptBASE64(src.getBytes(StandardCharsets.UTF_8));
        //对密文进行解密
        String decry = new String(decryBASE64(encrtypt));

        System.out.println(decry);
    }

}
